(in-package :lilu-mcclim-apropos)

;;;
;;;
;;;

(clim:define-presentation-type matched-system () :inherit-from '(matched-object))

(clim:define-presentation-method clim:present (object (type matched-system) stream
                                                      (view clim:textual-view)
                                                      &key acceptably for-context-type)
  (declare (ignore acceptably for-context-type))
  (princ (asdf:component-name object) stream))

;;;
;;;
;;;


(clim:define-application-frame system-apropos-frame (iapropos-application-frame)
  ()
  (:default-initargs
   :iapropos (make-instance 'asdf-iapropos)
   :presentation-type 'matched-system
   :object-name "System")
  (:command-table (system-apropos-frame-command-table
                   :inherit-from (iapropos-command-table
                                  iapropos-edit-command-table)
                   :menu (("Edit" :menu iapropos-edit-command-table)
                          ("Quit" :menu iapropos-command-table))))
  (:panes
   (system-result-display
    (make-ipropos-frame-matched-objects-pane))
   (system-output-display
    (make-ipropos-frame-selected-objects-pane))
   (system-name-regex-text-field
    (make-iapropos-frame-option-regex-pane :system-name-regex))
   (options
    (clim:labelling (:label "System")
      (clim:horizontally nil
        (clim:vertically nil
          (make-iapropos-frame-option-value-pane :loaded-p :vertical)
          (make-iapropos-frame-option-value-pane :description-p :vertical)
          (make-iapropos-frame-option-value-pane :version-p :vertical))
        (clim:vertically nil
          (make-iapropos-frame-option-value-pane :author-p :vertical)
          (make-iapropos-frame-option-value-pane :license-p :vertical)
          (make-iapropos-frame-option-value-pane :homepage-p :vertical)))))
   (selection-type
    (clim:labelling (:label "Selection")
      (make-iapropos-frame-selection-type-pane)))
   (actions (clim:labelling (:label "Actions")
              (make-iapropos-frame-action-pane))))
  (:layouts
   (:default
    (clim:vertically nil
      (3/5
       (clim:horizontally nil
         (clim:vertically nil
           options

           clim:+fill+)
         (clim:labelling (:label "Results")
           system-result-display)))
      (2/5
       (clim:horizontally nil
         (clim:vertically nil
           selection-type
           actions
           clim:+fill+)
         (clim:vertically nil
           (clim:labelling (:label "Output")
             system-output-display)
           (clim:labelling (:label "system apropos" :align-x :center)
             system-name-regex-text-field))))))))

(defun run-system-apropos (&key (new-process nil)
                               (width 790)
                               (height 550)
                               port
                               frame-manager
                               (pretty-name "System Apropos")
                             (process-name "system-apropos-frame"))
    (run-iapropos-application-frame 'system-apropos-frame
                                  :new-process new-process
                                  :width width
                                  :height height
                                  :port port
                                  :frame-manager frame-manager
                                  :pretty-name pretty-name
                                  :process-name process-name))
